/**
 * @author Renato Lui Geh
 * @author Yan Soares Couto
 * 
 * @version 0.0.1
 * 
 * 12/06/2011
 * 
 */

package zombies;

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.net.*;
import java.applet.*;

public class Map extends JPanel implements ActionListener {
    private final int mapWidth = 400;
    private final int mapHeight = 400;
    private static LinkedList mapNumber = new LinkedList();
    private javax.swing.Timer timer;
    private URL musicPath;
    private AudioClip backgroundMusic;
    
    public Player player;
    
    public static boolean createMap(int seed) {
        try {
            mapNumber.add(seed);
            return true;
        }
        catch(Exception exc) {
            exc.printStackTrace();
            return false;
        }
    }
    public Map(int mapNumber) {
        createMap(mapNumber);
        
        addKeyListener(new playerKeyAdapter());
        setFocusable(true);
        
        player = new Player();
        
        musicPath = this.getClass().getResource("musicBGe.wav");
        backgroundMusic = Applet.newAudioClip(musicPath);
        backgroundMusic.play();
        
        timer = new javax.swing.Timer(10, this);
        timer.start();
    }
    public Map() {
        addKeyListener(new playerKeyAdapter());
        setFocusable(true);
        setBackground(Color.BLACK);
        
        player = new Player();
        
        musicPath = this.getClass().getResource("musicBGe.wav");
        backgroundMusic = Applet.newAudioClip(musicPath);
        backgroundMusic.play();
        
        timer = new javax.swing.Timer(5, this);
        timer.start();
    }
    public void paint(Graphics graph) {
        super.paint(graph);
        
        Graphics2D g = (Graphics2D) graph;
        
        g.setColor(Color.GRAY);
        g.drawString("ALPHA TEST", 20, 20);
        g.setColor(Color.WHITE);
        g.drawString("Controls:", Zombies.WIDTH-200, 20);
        g.drawString("Movement: ARROW KEYS", Zombies.WIDTH - 200, 40);
        g.drawString("Attack: SPACEBAR", Zombies.WIDTH-200, 60);
        g.drawString("Block: B", Zombies.WIDTH-200, 80);
        
        g.drawImage(player.getImage(), 
                player.getX(), player.getY(),
                this);
        
        Toolkit.getDefaultToolkit().sync();
        g.dispose();
    }
    public void actionPerformed(ActionEvent ae) {
        player.move();
        repaint();
    }
    
    public class playerKeyAdapter extends KeyAdapter {
        public void keyPressed(KeyEvent key) {
            player.keyPressed(key);
        }
        public void keyReleased(KeyEvent key) {
            player.keyReleased(key);
        }
    }
}